<?php
namespace Home\Controller;
class SpaceController extends BaseController
{

    public function __construct() {
        parent::__construct();
        // $this->error("个人中心暂时未开放！",U('index/index'));
        // return false;
        $this->initCity();
        $this->assign("citys", $this->initCity());
        $this->assign("categorys", D('Category')->allCategory());
        //print_r($this->initCity());
    }

    public function index() {
        $this->display();
    }

    public function company() {
        $cModel = D("Company");
        if (IS_POST) {
            $map['name'] = I('post.title', "");
            $map['cid'] = I('post.cid', 0, "intval");
            $map['size'] = I('post.size', 0, "intval");
            $map['type'] = I("post.type", 0, "intval");
            $map['desc'] = I("post.content", "");
            $map['province'] = I("post.province", "");
            $map['city'] = I("post.city", "");
            $map['country'] = I("post.country", "");
            $map['address'] = I("post.address", "");
            $map['contact_user'] = I("post.contact_user", "");
            $map['contact_tel'] = I("post.contact_tel", "");
            $map['site_url'] = I("post.web_url", "");
            $id = I('post.id', 0, "intval");

            C('TOKEN_ON', false);
            $bool = $cModel->create($map);
            if ($bool == false) {
                $this->error($cModel->getError());
            }
            if ($id == 0) {//新增
                $cModel->uid = $this->userInfo['id'];
                $cModel->ctime = time();
                if ($cModel->add()) {
                    $this->success("企业信息新增成功！");
                } else {
                    $this->error("企业信息新增失败！");
                }
            } else {
                if ($cModel->where(array('id' => $id))->save()) {
                    $this->success("企业信息编辑成功！");
                } else {
                    $this->error("企业信息编辑失败！");
                }
            }
            die();

        }
        //检查用户是否已经编写过企业信息

        $this->assign("info", $cModel->getInfoByUid($this->userInfo['id']));
        print_r($cModel->getInfoByUid($this->userInfo['id']));
        $this->display();
    }

    //
    public function set() {
        $this->display();
    }
}